#pragma once

#include "common/PSingleton.h"
#include "2d/CCNode.h"
#include "ui/UIListView.h"
#include <map>
#include <vector>
#include <queue>

#include "GLGlobalDefine.h"
#include "CommonUiUtil.h"

class CCommonUiManager : public CSingleton<CCommonUiManager>
{
public:
	enum CommonNodeIndex {
		CGroupIndex,
	};

	enum NodeQueueIndex {
		NQIPropertyBroadcastReward,
		NQIPropertyBroadcastBattle,

		NQIPropertyBroadcastCount
	};
	struct RunProppertyBroadcastParam {
		RunProppertyBroadcastParam() : runNode(nullptr), max(0), value(0) {}
		cocos2d::Node*				runNode;
		uint8_t						max;
		cocos2d::Vec2				startPos;
		std::string					name;
		std::string					flag;
		int32_t						value;
	};

	struct BattleAnimalParam {
		bool						isUp;
		bool						isUser;
		GroupIndex					index;
	};

	struct ActionFrameRange {
		ActionFrameRange() : start(0), end(0) {}
		ActionFrameRange(int32_t _s, int32_t _e) : start(_s), end(_e) {}
		int32_t						start;
		int32_t						end;
	};
private:
	typedef std::map<int32_t, cocos2d::Node*>				MapNode_t;
	typedef std::vector<cocos2d::Node*>						VecNode_t;
	typedef std::queue<cocos2d::Node*>						QueNode_t;

	typedef std::map<int32_t, QueNode_t>					MapQueNode_t;
	typedef std::vector<ActionFrameRange>					VecActRange_t;
public:
	CCommonUiManager(void);
	~CCommonUiManager(void);

	cocos2d::Node* GetCommonNode(int32_t index);
	void RemCommonNode(int32_t index);

	cocos2d::ui::ListView* InitSkillView(cocos2d::Node* skillNode, SkillInfo* skill, int32_t start, int32_t end, CCommonUiUtil::VecNode_t& nodes);
	void RunPropertyBroadcast(const RunProppertyBroadcastParam& param);
	void RunPropertyBroadcast(const RunProppertyBroadcastParam& param, NodeQueueIndex type);
	cocos2d::Node* GetBattleAnimal(const BattleAnimalParam& param);
private:
	cocos2d::Node* getCacheNode(NodeQueueIndex index);
	void setCacheNode(NodeQueueIndex index, cocos2d::Node* node);
	cocos2d::Node* initNode(NodeQueueIndex index);

	void onSkillSelect(cocos2d::Ref* sender, cocos2d::ui::ListView::EventType type);
private:
	MapNode_t					m_Nodes;

	MapQueNode_t				m_QueNode;
	VecActRange_t				m_ActionRange;

	RunProppertyBroadcastParam	m_CurParam;
	VecNode_t					m_PropertyBroadcast;
	VecNode_t					m_BattleAnimal;
};

